package cn.star.jots.actor.controller;

import cn.star.jots.actor.pojo.dto.ActorQuery;
import cn.star.jots.actor.pojo.dto.ActorSaveParam;
import cn.star.jots.actor.pojo.vo.ActorVO;
import cn.star.jots.actor.service.ActorService;
import cn.star.jots.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/actor")
@Api(tags = "演员管理")
@Slf4j
public class ActorController {

    @Autowired
    ActorService actorService;

    @GetMapping("/select")
    @ApiOperation(value = "查询演员列表")
    public JsonResult select(ActorQuery actorQuery) {
       log.info("查询演员列表:actorQuery={}", actorQuery);
        List<ActorVO> list = actorService.selectAll(actorQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存演员信息")
    public JsonResult save(ActorSaveParam actorSaveParam) {
        log.info("保存演员信息:actorVO={}", actorSaveParam);
        actorService.save(actorSaveParam);
        return JsonResult.ok();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据ID删除演员信息")
    public JsonResult deleteById(@PathVariable Long id) {
        log.info("根据ID删除演员信息:id={}", id);
        actorService.deleteById(id);
        return JsonResult.ok();
    }
}
